package Personal;

import java.io.File;

import Context.Constant;
import Context.XmlParser;
import Data.User;
import Data.UserCategory;
import Data.UserGroup;

class ContractGroups {
	ContractGroups() {
		userCategory = null;
		loadCategory();
	}

	private UserCategory userCategory;

	void loadCategory() {
		XmlParser xmlParser = new XmlParser(new File(Constant.PERSONALCONFIG));
		userCategory = xmlParser.parseCategory();
	}

	UserCategory getUserCategory() {
		return userCategory;
	}

	void saveCategory() {
		XmlParser xmlParser = new XmlParser(new File(Constant.PERSONALCONFIG));
		xmlParser.saveGroupUsers(userCategory);
	}
	User findTheUser(String ip) {
		for (UserGroup userGroup : userCategory.getAllgroups()) {
			for(User currentUser : userGroup.getGroupUsers()) {
				if(currentUser.getIp().equals(ip))
					return currentUser;
			}
		}
		return null;
	}

}
